<template>
  <div class="layout">
    <Layout>
      <Header class="index-header">
        <Row type="flex" justify="end" class="code-row-bg">
          <Col span="3" v-if="!isLogin">
            还没有账号？
            <a href="javascript:void(0)" @click="showRegModal">立即注册</a>
          </Col>
          <span v-if="!isLogin">|</span>
          <Col span="1" v-if="!isLogin"><a href="javascript:void(0)" @click="showLoginModal">登录</a></Col>

          <Col span="5" v-if="isLogin" class="userInfo">
            <Avatar :src="user.avatarImgPath"></Avatar>
            <strong>{{ user.userName }}</strong>欢迎您
          </Col>
          <span v-if="isLogin">|</span>
          <Col span="1" v-if="isLogin">
            <Badge dot :offset="[15,-3]">
              <a href="#" class="demo-badge">消息</a>
            </Badge>
          </Col>
          <span v-if="isLogin">|</span>
          <Col span="2" v-if="isLogin">
            <Dropdown>
              <a href="javascript:void(0)">
                我的
                <Icon type="ios-arrow-down"></Icon>
              </a>
              <DropdownMenu slot="list">
                <DropdownItem>个人信息</DropdownItem>
                <DropdownItem>我的订单</DropdownItem>
                <DropdownItem>我的收藏</DropdownItem>
                <DropdownItem>会员中心</DropdownItem>
              </DropdownMenu>
            </Dropdown>
          </Col>
          <span>|</span>
          <Col span="2"><a href="javascript:void(0)">客户中心</a></Col>
        </Row>
      </Header>
      <Content class="index-content">
        <Header class="index-content-header">
          <Row>
            <Col span="2" offset="4" class="icon"><img src="https://glkj.top/static/logo.png" alt="贵龙科技"></Col>
            <Col span="8" offset="2" class="hotelName text-center">
              <h1>贵龙科技艺苑酒店</h1>
            </Col>
            <Col span="6">
              <Row type="flex" justify="end" class="phone-list">
                <Col span="4" class="phone-title">
                  <Avatar shape="square" size="large" style="background: #2d8cf0">联系方式</Avatar>
                </Col>
                <Col span="13" class="phone-value">
                  <ul>
                    <li>1325556556</li>
                    <li>1325556556</li>
                    <li>1325556556</li>
                    <li>1325556556</li>
                  </ul>
                </Col>
              </Row>
            </Col>
          </Row>
        </Header>
        <main>
          <div class="banner text-left">
            <Carousel :autoplay="setting.autoplay"
                      :autoplay-speed="setting.autoplaySpeed"
                      :dots="setting.dots"
                      :radius-dot="setting.radiusDot"
                      :trigger="setting.trigger"
                      :arrow="setting.arrow" v-model="value" loop style="width: 100%">
              <CarouselItem>
                <img src="http://localhost:8820/api/api/img/index/1.jpg" width="100%" height="350px"/>
              </CarouselItem>
              <CarouselItem>
                <img src="http://localhost:8820/api/api/img/index/2.jpg" width="100%" height="350px"/>
              </CarouselItem>
              <CarouselItem>
                <img src="http://localhost:8820/api/api/img/index/3.jpg" width="100%" height="350px"/>
              </CarouselItem>
              <CarouselItem>
                <img src="http://localhost:8820/api/api/img/index/4.jpg" width="100%" height="350px"/>
              </CarouselItem>
            </Carousel>

          </div>
          <Row class="text-center">
            <Col class="panel">
              <Divider plain><p class="panel-title color-a">精选好房</p></Divider>
              <RoomItem v-for="i in roomData" :key="i.id" class="text-center"

              ></RoomItem>

            </Col>
            <Col class="panel">
              <Divider plain><p class="panel-title color-b">会员优势</p></Divider>
              <Card class="vip">
                <h1 class="color-e">优先订房</h1>
                <h1 class="color-f">无忧退订</h1>
                <h1 class="color-g">特定折扣</h1>
                <h1 class="color-h">快捷入住</h1>
              </Card>
            </Col>
            <Col class="panel">
              <Divider plain><p class="panel-title color-c">活动推荐</p></Divider>

            </Col>
            <Col class="panel">
              <Divider plain><p class="panel-title color-d">酒店合作</p></Divider>

            </Col>
          </Row>
        </main>
      </Content>
      <Footer class="index-footer">
        <Row>
          <Col span="24" class="text-center">
            COPYRIGHT © 2019-2025 XGL. ALL RIGHTS RESERVED. <a href="https://glkj.top">贵龙科技</a>
          </Col>
          <Col span="11" class="text-right">
            Thank For <a href="https://www.iviewui.com/">View Ui</a> and <a href="https://admin.iviewui.com/login">View-Admin</a>
          </Col>
          <Col offset="2" span="11" class="text-left">
            ICP网备：<a href="http://www.beian.miit.gov.cn/" type="target">渝ICP备18014747号</a>
          </Col>
        </Row>
      </Footer>
    </Layout>
    <login ref="login" @showReg="showRegModal" @refresh="checkLogin"></login>
    <register ref="reg"></register>
  </div>
</template>

<script>
import login from "@/view/customer/login";
import register from "@/view/customer/register";
import HouseItem from "@/view/admin/room/HouseItem";
import {isVariable} from "@/libs/util";
import minLogo from '@/assets/images/logo-min.png'
import {mapActions} from "vuex";
import RoomItem from "@/view/customer/RoomItem";

export default {
  name: "Index",
  components: {
    login,
    register,
    HouseItem,
    RoomItem
  },
  data() {
    return {
      value: 0,
      setting: {
        autoplay: true,
        autoplaySpeed: 4000,
        dots: 'inside',
        radiusDot: false,
        trigger: 'click',
        arrow: 'hover'
      },
      isLogin: false,
      user: {userName: '', id: '', avatarImgPath: minLogo},
      roomData: [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}, {id: 9}, {id: 10}, {id: 11}, {id: 12}],
    }
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    showRegModal() {
      this.$refs.reg.showRegForm();
    },
    showLoginModal() {
      this.$refs.login.showLoginForm();
    },
    showLogin() {
      this.isLogin = true;
      this.user.userName = this.$store.state.userName;
      this.user.id = this.$store.state.userId;
      this.user.token = this.$store.state.token;
      this.user.avatarImgPath = this.$store.state.avatarImgPath;
    },
    showNoLogin() {
      this.isLogin = false;
      this.user = {userName: '', id: '', token: '', avatarImgPath: minLogo};
    },
    checkLogin() {
      this.getUserInfo().then(res => {
        let userName = res.username;
        this.user.userName = this.$store.state.userName = isVariable(userName) ? userName : this.$store.state.userName;
        let id = res.id;
        this.user.id = this.$store.state.userId = isVariable(id) ? id : this.$store.state.userId;
        let img = res.avatarImgPath;
        this.user.avatarImgPath = this.$store.state.avatarImgPath = isVariable(img) ? img : this.$store.state.avatarImgPath;
        this.showLogin();
      }).catch(e => {
        this.showNoLogin();
        this.$Message.error(e);
      })
    }
  },
  mounted() {
    this.checkLogin();
  }
}
</script>

<style scoped lang="less">
ul, ol, li {
  list-style: none;
}

.panel {
  .panel-title {
    font-size: 28px;
    font-weight: bold;
  }
}

.userInfo {
  font-size: 16px;

  strong {
    margin: 0 10px;
  }
}

.vip {
  width: 94%;
  margin-left: auto;
  margin-right: auto;
  h1{
    display: inline-block;
    width: 22%;
    font-family: 'Operator Mono', 'Source Code Pro', Menlo, Monaco, Consolas, Courier New, monospace;
  }
}

.index-header {
  height: 44px;
  background: rgba(240, 240, 240, 0.3);

  > * {
    color: rgba(22, 22, 22, 0.8);
    font-size: 12px;
    text-align: center;
    height: 44px;
    line-height: 44px;
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  }
}

.color-a {
  background-image: -webkit-linear-gradient(bottom, palevioletred, red, #9b1dea, #13c2c2, #9b1dea);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.color-b {
  background-image: -webkit-linear-gradient(bottom, greenyellow, #2b85e4, green);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.color-c {
  background-image: -webkit-linear-gradient(bottom, #87e8de, #6a9fb5, #000000);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.color-d {
  background-image: -webkit-linear-gradient(bottom, red, #9b1dea, #0000ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.color-e {
  background-image: -webkit-linear-gradient(bottom, #af7dff, #221199, #00bb00,#6a9fb5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.color-f {
  background-image: -webkit-linear-gradient(bottom, #00ffff, #2d8cf0, #5d6c7b,#2f54eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.color-g {
  background-image: -webkit-linear-gradient(bottom, #8f5536, #795da3, #67647D,#3300aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.color-h {
  background-image: -webkit-linear-gradient(bottom, #ac4142, #2f54eb, #1F2D3D,#505050);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.banner img {
  width: 100%;
}

.index-content {
  min-height: 75vh;
  height: 100%;

  > .index-content-header {
    height: 72px;
    background: rgba(255, 255, 255, 0.9);

    .icon {
      img {
        margin: 14px 0;
        width: 100%;
        height: 44px;
      }
    }

    .phone-list {
      margin: unset;
      height: 72px;
      overflow: hidden;

      .phone-value {
        margin-top: 10px;

        ul {
          line-height: 20px;
          height: 20px;

          li {
            display: inline-block;
            margin: 2px 6px;
          }
        }
      }
    }
  }
}

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.index-footer {
  background: rgba(240, 240, 240, 0.8);
  color: rgba(75, 75, 75, 0.4);
}

main {
  height: 100%;
}
</style>
<style>
.ivu-carousel-list {
  width: 80% !important;
  margin: auto;
}

html, body {
  overflow: unset;
  margin: 0;
  padding: 0;
}
</style>
